package com.cmrx.model.service.impl;

import java.text.SimpleDateFormat;
import java.util.*;

import com.cmrx.model.dao.*;
import com.cmrx.model.entity.*;
import com.cmrx.model.service.AnalysisService;
import com.cmrx.model.util.UUIDUtil;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cmrx.model.service.InvestigationService;
import org.springframework.util.StringUtils;

@Service
@Transactional
public class InvestigationServiceImpl implements InvestigationService{
	
	@Autowired
	private InvestigationDao investigationDao;
	@Autowired
	private AnalysisService analysisService;
    @Autowired
    private OpSceneAnalysisDao opSceneAnalysisDao;
    @Autowired
    private SceneBioEvidenceDao sceneBioEvidenceDao;
    @Autowired
    private SceneVideoEvidenceDao sceneVideoEvidenceDao;
    @Autowired
    private SceneFootPrintDao sceneFootPrintDao;
    @Autowired
    private LoginDao loginDao;


	@Override
	public List<CaseDetail> selectListLawCase(String userid, String investigationid) {
		
		List<CaseDetail> list = investigationDao.selectListLawCase(userid, investigationid);
		
		if(StringUtil.isNotEmpty(investigationid)&&!list.isEmpty()) {
			List<Witness> wList = investigationDao.selectWitnessesByInvestigationid(investigationid);
			list.get(0).setWitnesseList(wList);
			List<LostGoods> lGoods = investigationDao.selectLostGoodsByInvestigationid(investigationid);
			list.get(0).setLostGoodsList(lGoods);
			String caseid = list.get(0).getCaseid();
			List<Victim> vList = investigationDao.selectVictimsByCaseId(caseid);
			list.get(0).setVictimsList(vList);
			String casetype = list.get(0).getCase_type();
			String regionalism = list.get(0).getScene_regionalism();
			String techid = "";
			if(StringUtil.isNotEmpty(casetype)&&StringUtil.isNotEmpty(regionalism)){
                List<String> infoList = investigationDao.selectInfoIds(techid, casetype, regionalism);
                if(!infoList.isEmpty()) {
                    list.get(0).setInfoids(infoList.get(0));
                }
            }
            if(StringUtils.isEmpty(list.get(0).getInfoids())){
                if(StringUtil.isNotEmpty(casetype)){
                    List<String> infoList = investigationDao.selectInfoIds(techid, casetype, "");
                    if(!infoList.isEmpty()) {
                        list.get(0).setInfoids(infoList.get(0));
                    }
                }
            }
		}
		return list;
	}

	@Override
	public Map<String, Object> addCase(String userid,String username,String organize,String techid,String userCard) {
		
		Date date = new Date();
		SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = sFormat.format(date);
		String caseid = UUIDUtil.getUUID();

		String receptionid = UUIDUtil.getUUID();
        Map<String, Object> param = new HashMap<String, Object>();
        Organize organization = loginDao.selectOrganize(userCard);
        param.put("organizeReglism",organization.getRegionalism());
		CaseDetail caseDetail = new CaseDetail();
		caseDetail.setReception_id(receptionid);
		caseDetail.setCreate_user(username);
		caseDetail.setComtime(time);
		caseDetail.setReceived_by(organize);
		caseDetail.setAssigned_way_s("1");
        caseDetail.setScene_regionalism(organization.getRegionalism());

		investigationDao.insertReceptionDispatch(caseDetail);
		
		param.put("userid", userid);
		param.put("receptionid", receptionid);
		param.put("username", username);
		param.put("caseid", caseid);
		param.put("time", time);
		param.put("techid", techid);
        param.put("duties", techid+","+"2");

		investigationDao.addLawCase(param);
		
		String investigationid = UUIDUtil.getUUID();
		param.put("investigationid", investigationid);
        param.put("organizeId",organization.getId());
        param.put("organizeName",organization.getOrganName());

		investigationDao.addInvestigation(param);

		String analysisSuggestid = UUIDUtil.getUUID();
		param.put("analysisSuggestid", analysisSuggestid);
		param.put("analysed_org",organize);
		investigationDao.addAnalysis(param);
        param.put("analysisSuggestid", UUIDUtil.getUUID());
        opSceneAnalysisDao.addOpAnalysisByMap(param);


		Map<String, Object> map = new HashMap<String, Object>();



		map.put("investigationid", investigationid);
		map.put("caseid", caseid);
		return map;
	}

	@Override
	public void deleteCase(String investigationid,String caseid) {
		investigationDao.deleteCase(caseid);
		investigationDao.deleteInvestigation(investigationid);
	}

	@Override
	public String updateCase(CaseDetail caseDetail) {
		Date date = new Date();
		SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = sFormat.format(date);
		caseDetail.setComtime(time);
		//填数据update|add COMMON_ATTACHMENT
//		if(StringUtil.isNotEmpty(caseDetail.getUpdated_invest_note_id())) {
//			investigationDao.updateAttachment(caseDetail);
//		}else {
//			if(StringUtil.isNotEmpty(caseDetail.getInvestigationconect())) {
//				String updated_invest_note_id = UUIDUtil.getUUID();
//				caseDetail.setUpdated_invest_note_id(updated_invest_note_id);
//				investigationDao.insertAttachment(caseDetail);
//			}
//		}

		//填数据update|add common_bigtext_clob   INVEST_NOTE_ID,casecontent
		if(StringUtil.isNotEmpty(caseDetail.getInvest_note_id())) {
			investigationDao.updateBigtextClob(caseDetail);
		}else {
			if(StringUtil.isNotEmpty(caseDetail.getInvestigationconect())) {
				String invest_note_id = UUIDUtil.getUUID();
				caseDetail.setInvest_note_id(invest_note_id);
				investigationDao.insertBigtextClob(caseDetail);
			}
		}

		/*警情表时间处理*/
        String rd = caseDetail.getReceived_date();
        String dd = caseDetail.getDispatch_date();
        if(!StringUtils.isEmpty(rd)){
            rd = rd.replaceAll("年","-").replaceAll("月","-").replaceAll("日","");
            caseDetail.setReceived_date(rd);
        }
        if(!StringUtils.isEmpty(dd)){
            dd = dd.replaceAll("年","-").replaceAll("月","-").replaceAll("日","");
            caseDetail.setDispatch_date(dd);
        }
        String odt = caseDetail.getOccurrence_date_to();
        if(!StringUtils.isEmpty(odt)){
            odt = odt.replaceAll("年","-").replaceAll("月","-").replaceAll("日","");
            caseDetail.setOccurrence_date_to(odt);
        }
        String odf = caseDetail.getOccurrence_date_from();
        if(!StringUtils.isEmpty(odf)){
            odf = odf.replaceAll("年","-").replaceAll("月","-").replaceAll("日","");
            caseDetail.setOccurrence_date_from(odf);
        }
        String idt = caseDetail.getInvestigation_date_to();
        if(!StringUtils.isEmpty(idt)){
            idt = idt.replaceAll("年","-").replaceAll("月","-").replaceAll("日","");
            caseDetail.setInvestigation_date_to(idt);
        }
        String idf = caseDetail.getInvestigation_date_from();
        if(!StringUtils.isEmpty(idf)){
            idf = idf.replaceAll("年","-").replaceAll("月","-").replaceAll("日","");
            caseDetail.setInvestigation_date_from(idf);
        }
        String pd = caseDetail.getProtection_date();
        if(!StringUtils.isEmpty(pd)){
            pd = pd.replaceAll("年","-").replaceAll("月","-").replaceAll("日","");
            caseDetail.setProtection_date(pd);
        }
		//填数据update|add scene_reception_dispatch	
		if(StringUtil.isNotEmpty(caseDetail.getReception_id())) {
			investigationDao.updateReceptionDispatch(caseDetail);
		}else {
			if(StringUtil.isNotEmpty(caseDetail.getReceived_date())
				|| StringUtil.isNotEmpty(caseDetail.getDispatch_date())
				|| StringUtil.isNotEmpty(caseDetail.getReceived_by())
				|| StringUtil.isNotEmpty(caseDetail.getAssigned_by())
				|| StringUtil.isNotEmpty(caseDetail.getAssigned_way_s())
				|| StringUtil.isNotEmpty(caseDetail.getAssigned_way_t())
				|| StringUtil.isNotEmpty(caseDetail.getAssigned_content())){
				
				String reception_id = UUIDUtil.getUUID();
				caseDetail.setReception_id(reception_id);
				investigationDao.insertReceptionDispatch(caseDetail);
			}
		}
		//填数据update scene_law_case
		investigationDao.updateLawCase(caseDetail);
		//填数据update scene_investigation
		investigationDao.updateInvestigation(caseDetail);

        //案件信息如果法发案地点变动分析意见也变动
        investigationDao.updateAnalysisPlace(caseDetail);

		String casetype = caseDetail.getCase_type();
		String regionalism = caseDetail.getScene_regionalism();
		String techid = "";
		if(StringUtil.isNotEmpty(casetype)||StringUtil.isNotEmpty(regionalism)) {
			List<String> infoList = investigationDao.selectInfoIds(techid, casetype, regionalism);
			if(!infoList.isEmpty()){
				return infoList.get(0);
			}
		}

		return "";
	}

	@Override
	public Witness addOrUpdateWitness(Witness witness) {
		if(StringUtil.isNotEmpty(witness.getId())) {
			investigationDao.updateWitness(witness);
		}else {
			//查询数量
			int count = investigationDao.selectCountWitness(witness.getInvestigationId());
			Date date = new Date();
			SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String time = sFormat.format(date);
			witness.setCreateDatetime(time);
			witness.setSerialNo(String.valueOf(count++));
			String id = UUIDUtil.getUUID();
			witness.setId(id);
			investigationDao.insertWitness(witness);
		}
		return witness;
	}

	@Override
	public void deleteWitness(Witness witness) {
		investigationDao.deleteWitness(witness);
	}

	@Override
	public LostGoods addOrUpdateLostgoods(LostGoods lostGoods,User user) {
		if(StringUtil.isNotEmpty(lostGoods.getId())) {
			investigationDao.updateLostgoods(lostGoods);
		}else {
			//查询已有数量
			int count = investigationDao.selectCountLostgoods(lostGoods.getInvestigation_id());
			Date date = new Date();
			SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String time = sFormat.format(date);
			lostGoods.setCreate_datetime(time);
			lostGoods.setSerial_no(String.valueOf(count++));
			String id = UUIDUtil.getUUID();
			lostGoods.setId(id);
			investigationDao.insertLostgoods(lostGoods);
		}
		return lostGoods;
	}

	@Override
	public void deleteLostgoods(LostGoods lostGoods) {
		investigationDao.deleteLostgoods(lostGoods);
	}

	@Override
	public Victim addOrUpdateVictim(Victim victim,User user) {
		if(victim.getAge()==""){
			victim.setAge(null);
		}
		if(StringUtil.isNotEmpty(victim.getId())) {
			investigationDao.updateVictim(victim);
		}else {
			Date date = new Date();
			SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String time = sFormat.format(date);
			victim.setCreateDatetime(time);
			String id = UUIDUtil.getUUID();
			victim.setId(id);
			investigationDao.insertVictim(victim);
		}
		return victim;
	}

	@Override
	public void deleteVictim(Victim victim) {
		investigationDao.deleteVictim(victim);
	}

	@Override
	public Map<String,Object> submitCase(CaseDetail caseDetail,User user) {
		Map<String,Object> map = new HashMap<>();
		List<String> list = new ArrayList<String>();
        int scenePictureAmount = 0;
        int scenePhotoAmount = 0;
        String infoIds = caseDetail.getInfoids();
        String deadAmount = caseDetail.getDead_amount();
        //死亡数量大于1 按14类案件处理
        int deadCount = 0;
        if(!StringUtils.isEmpty(deadAmount)){
           // "^\\d+$" //非负整数（正整数   +   0）
            if(deadAmount.matches("^\\d+$")){
                deadCount = Integer.valueOf(deadAmount);
                if(deadCount>0){
                    infoIds ="";
                    caseDetail.setInfoids("");
                }
            }
        }
        if(StringUtils.isEmpty(infoIds)){
            if(StringUtils.isEmpty(caseDetail.getCase_no())){
                list.add("警情编号不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getCase_type())){
                list.add("案发类别不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getScene_regionalism())){
                list.add("发案区划不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getScene_detail())){
                list.add("发案地点不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getOccurrence_date_from())){
                list.add("开始发案时间不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getOccurrence_date_to())){
                list.add("结束发案时间不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getAssigned_by())){
                list.add("指派单位/人不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getAssigned_way_s())&&StringUtils.isEmpty(caseDetail.getAssigned_way_t())){
                list.add("指派方式不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getScene_condition())){
                list.add("现场条件不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getLighting())){
                list.add("光照条件不能为空");
            }
            if(!StringUtils.isEmpty(caseDetail.getProtector())){
                String [] strings = caseDetail.getProtector().split("&amp");
                int a = strings.length;
                if(a==0){
                    list.add("保护人单位不能为空");
                    list.add("保护人不能为空");
                    list.add("保护人职务不能为空");
                }else if(a==1){
                    list.add("保护人不能为空");
                    list.add("保护人职务不能为空");
                }else if(a==2){
                    if(StringUtils.isEmpty(strings[0])){
                        list.add("保护人单位不能为空");
                    }
                    list.add("保护人职务不能为空");
                }else if(a==3){
                    if(StringUtils.isEmpty(strings[0])){
                        list.add("保护人单位不能为空");
                    }
                    if(StringUtils.isEmpty(strings[1])){
                        list.add("保护人不能为空");
                    }
                }
            }else {
                list.add("保护人单位不能为空");
                list.add("保护人不能为空");
                list.add("保护人职务不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getReserver6())){
                list.add("保护措施不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getCasecontent())){
                list.add("案件发现过程不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getInvestigationconect())){
                list.add("勘验检查情况不能为空");
            }/*else {
                if(caseDetail.getInvestigationconect().length()<200){
                    list.add("勘验检查情况必须大于200字");
                }
            }*/
            if(StringUtils.isEmpty(caseDetail.getReceived_date())){
                list.add("接勘时间不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getAssigned_content())){
                list.add("指派内容不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getInvestigation_place())){
                list.add("勘验地点不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getInvestigation_date_from())){
                list.add("开始勘验时间不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getInvestigation_date_to())){
                list.add(" 结束勘验时间不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getWeather())){
                list.add("现场天气不能为空");
            }
            if(StringUtils.isEmpty(caseDetail.getInvestigator())){
                list.add("勘验检查人员不能少于两人");
            }else {
                if(caseDetail.getInvestigator().split(",").length<2){
                    list.add("勘验检查人员不能少于两人");
                }
            }
            scenePictureAmount = investigationDao.selectCountPicture(caseDetail.getInvestigationid());
            scenePhotoAmount = investigationDao.selectCountPhoto(caseDetail.getInvestigationid());
            //14类案件匹配不到模板
            if(StringUtils.isEmpty(caseDetail.getInfoids())){
                if(scenePictureAmount<2){
                    list.add("14类案件现场图不能少于两张");
                }
                if(scenePhotoAmount<4){
                    list.add("14类案件现场照片不能少于四张");
                }
                if(caseDetail.getWitnesseList().size()<2){
                    list.add("14类案件见证人至少有两位");
                }
            }else {
                if(scenePictureAmount<1){
                    list.add("案件现场图不能少于1张");
                }
                if(scenePhotoAmount<1){
                    list.add("案件现场照片不能少于1张");
                }
                if(caseDetail.getWitnesseList().size()<1){
                    list.add("案件见证人至少有1位");
                }
            }
        }else {
            String [] caseInfoIds = infoIds.split(",");
            List caseInfoIdsList = Arrays.asList(caseInfoIds);
            if(caseInfoIdsList.contains("1")){
                if(StringUtils.isEmpty(caseDetail.getCase_no())){
                    list.add("警情编号不能为空");
                }
            }
            if(caseInfoIdsList.contains("3")){
                if(StringUtils.isEmpty(caseDetail.getCase_type())){
                    list.add("案发类别不能为空");
                }
            }
            if(caseInfoIdsList.contains("4")){
                if(StringUtils.isEmpty(caseDetail.getScene_regionalism())){
                    list.add("发案区划不能为空");
                }
            }
            if(caseInfoIdsList.contains("5")){
                if(StringUtils.isEmpty(caseDetail.getScene_detail())){
                    list.add("发案地点不能为空");
                }
            }
            if(caseInfoIdsList.contains("6")){
                if(StringUtils.isEmpty(caseDetail.getOccurrence_date_from())){
                    list.add("开始发案时间不能为空");
                }
                if(StringUtils.isEmpty(caseDetail.getOccurrence_date_to())){
                    list.add("结束发案时间不能为空");
                }
            }
            if(caseInfoIdsList.contains("12")){
                if(StringUtils.isEmpty(caseDetail.getAssigned_by())){
                    list.add("指派单位/人不能为空");
                }
            }
            if(caseInfoIdsList.contains("13")){
                if(StringUtils.isEmpty(caseDetail.getAssigned_way_s())&&StringUtils.isEmpty(caseDetail.getAssigned_way_t())){
                    list.add("指派方式不能为空");
                }
            }
            if(caseInfoIdsList.contains("21")){
                if(StringUtils.isEmpty(caseDetail.getScene_condition())){
                    list.add("现场条件不能为空");
                }
            }
            if(caseInfoIdsList.contains("22")){
                if(StringUtils.isEmpty(caseDetail.getLighting())){
                    list.add("光照条件不能为空");
                }
            }
            if(!StringUtils.isEmpty(caseDetail.getProtector())){
                String [] strings = caseDetail.getProtector().split("&amp");
                int a = strings.length;
                if(a==0){
                    if(caseInfoIdsList.contains("26")){
                        list.add("保护人单位不能为空");
                    }
                    if(caseInfoIdsList.contains("25")){
                        list.add("保护人不能为空");
                    }
                    if(caseInfoIdsList.contains("27")){
                        list.add("保护人职务不能为空");
                    }
                }else if(a==1){
                    if(caseInfoIdsList.contains("25")){
                        list.add("保护人不能为空");
                    }
                    if(caseInfoIdsList.contains("27")){
                        list.add("保护人职务不能为空");
                    }
                }else if(a==2){
                    if(caseInfoIdsList.contains("26")) {
                        if (StringUtils.isEmpty(strings[0])) {
                            list.add("保护人单位不能为空");
                        }
                    }
                    if(caseInfoIdsList.contains("27")){
                        list.add("保护人职务不能为空");
                    }
                }else if(a==3){
                    if(caseInfoIdsList.contains("26")) {
                        if(StringUtils.isEmpty(strings[0])){
                            list.add("保护人单位不能为空");
                        }
                    }
                    if(caseInfoIdsList.contains("25")) {
                        if (StringUtils.isEmpty(strings[1])) {
                            list.add("保护人不能为空");
                        }
                    }
                }
            }else {
                if(caseInfoIdsList.contains("26")){
                    list.add("保护人单位不能为空");
                }
                if(caseInfoIdsList.contains("25")){
                    list.add("保护人不能为空");
                }
                if(caseInfoIdsList.contains("27")){
                    list.add("保护人职务不能为空");
                }
            }
            if(caseInfoIdsList.contains("28")){
                if(StringUtils.isEmpty(caseDetail.getReserver6())){
                    list.add("保护措施不能为空");
                }
            }
            if(caseInfoIdsList.contains("29")){
                if(StringUtils.isEmpty(caseDetail.getCasecontent())){
                    list.add("案件发现过程不能为空");
                }
            }
            if(caseInfoIdsList.contains("30")){
                if(StringUtils.isEmpty(caseDetail.getInvestigationconect())){
                    list.add("勘验检查情况不能为空");
                }/*else {
                    if(caseDetail.getInvestigationconect().length()<200){
                        list.add("勘验检查情况必须大于200字");
                    }
                }*/
            }
            if(caseInfoIdsList.contains("10")){
                if(StringUtils.isEmpty(caseDetail.getReceived_date())){
                    list.add("接勘时间不能为空");
                }
            }
            if(caseInfoIdsList.contains("14")){
                if(StringUtils.isEmpty(caseDetail.getAssigned_content())){
                    list.add("指派内容不能为空");
                }
            }
            if(caseInfoIdsList.contains("19")){
                if(StringUtils.isEmpty(caseDetail.getInvestigation_place())){
                    list.add("勘验地点不能为空");
                }
            }
            if(caseInfoIdsList.contains("16")){
                if(StringUtils.isEmpty(caseDetail.getInvestigation_date_from())){
                    list.add("开始勘验时间不能为空");
                }
                if(StringUtils.isEmpty(caseDetail.getInvestigation_date_to())){
                    list.add(" 结束勘验时间不能为空");
                }
            }
            if(caseInfoIdsList.contains("20")){
                if(StringUtils.isEmpty(caseDetail.getWeather())){
                    list.add("现场天气不能为空");
                }
            }
            if(caseInfoIdsList.contains("40")){
                if(StringUtils.isEmpty(caseDetail.getInvestigator())){
                    list.add("勘验检查人员不能少于两人");
                }else {
                    if(caseDetail.getInvestigator().split(",").length<2){
                        list.add("勘验检查人员不能少于两人");
                    }
                }
            }

             scenePictureAmount =  investigationDao.selectCountPicture(caseDetail.getInvestigationid());
             scenePhotoAmount = investigationDao.selectCountPhoto(caseDetail.getInvestigationid());
              /*  scenePictureAmount = 4;
                scenePhotoAmount = 4;*/
            //14类案件匹配不到模板
            if(StringUtils.isEmpty(caseDetail.getInfoids())){
                if(scenePictureAmount<2){
                    list.add("14类案件现场图不能少于两张");
                }
                if(scenePhotoAmount<4){
                    list.add("14类案件现场照片不能少于四张");
                }
                if(caseDetail.getWitnesseList().size()<2){
                    list.add("14类案件见证人至少有两位");
                }
            }else {
                if(scenePictureAmount<1){
                    list.add("案件现场图不能少于1张");
                }
                if(scenePhotoAmount<1){
                    list.add("案件现场照片不能少于1张");
                }
                if(caseDetail.getWitnesseList().size()<1){
                    list.add("案件见证人至少有1位");
                }
            }
        }
		map.put("caseDetail",list);

		AnalysisSuggestion analysisSuggestion = analysisService.selectAnalysisSuggestionById(caseDetail,"");
		String suggInfoIds = analysisSuggestion.getInfoids();

        if(!StringUtils.isEmpty(deadAmount)){
            // "^\\d+$" //非负整数（正整数   +   0）
            if(deadAmount.matches("^\\d+$")){
                deadCount = Integer.valueOf(deadAmount);
                if(deadCount>0){
                    suggInfoIds ="";
                    analysisSuggestion.setInfoids("");
                }
            }
        }


		List<String> listSuggestion = new ArrayList<String>();
		if(StringUtils.isEmpty(suggInfoIds)){
            if(analysisSuggestion==null){
                listSuggestion.add("选择对象为必填项");
                listSuggestion.add("选择处所为必填项");
                listSuggestion.add("作案时机为必填项");
                listSuggestion.add("作案入口为必填项");
                listSuggestion.add("作案出口为必填项");
                listSuggestion.add("作案手段为必填项");
                listSuggestion.add("侵入方式为必填项");
                listSuggestion.add("作案特点为必填项");
                listSuggestion.add("案件性质为必填项");
                listSuggestion.add("作案动机目的为必填项");
                listSuggestion.add("作案过程为必填项");
                listSuggestion.add("作案人特点为必填项");
                listSuggestion.add("关于侦查方向与范围、侦破措施及途径等意见为必填项");
            }else {
                if(StringUtils.isEmpty(analysisSuggestion.getIntention_cn())&&StringUtils.isEmpty(analysisSuggestion.getIntention_desc())){
                    listSuggestion.add("选择对象为必填项");
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getIntention_cn())){
                        if((analysisSuggestion.getIntention_cn().contains("其他")||analysisSuggestion.getIntention_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getIntention_desc())){
                            listSuggestion.add("选择对象包含其他，手填项必填");
                        }
                    }
                }

                if(StringUtils.isEmpty(analysisSuggestion.getLocation_cn())&&StringUtils.isEmpty(analysisSuggestion.getLocation_desc())){
                    listSuggestion.add("选择处所为必填项");
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getLocation_cn())){
                        if((analysisSuggestion.getLocation_cn().contains("其他")||analysisSuggestion.getLocation_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getLocation_desc())){
                            listSuggestion.add("选择处所包含其他，手填项必填");
                        }
                    }
                }

                if(StringUtils.isEmpty(analysisSuggestion.getCommission_period_cn())&&StringUtils.isEmpty(analysisSuggestion.getCommission_period_desc())){
                    listSuggestion.add("作案时机为必填项");
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getCommission_period_cn())){
                        if((analysisSuggestion.getCommission_period_cn().contains("其他")||analysisSuggestion.getCommission_period_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getCommission_period_desc())){
                            listSuggestion.add("作案时机包含其他，手填项必填");
                        }
                    }
                }

                if(StringUtils.isEmpty(analysisSuggestion.getEntrance_exit_cn())&&StringUtils.isEmpty(analysisSuggestion.getEntrance_exit_desc())){
                    listSuggestion.add("作案入口为必填项");
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getEntrance_exit_cn())){
                        if((analysisSuggestion.getEntrance_exit_cn().contains("其他")||analysisSuggestion.getEntrance_exit_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getEntrance_exit_desc())){
                            listSuggestion.add("作案入口包含其他，手填项必填");
                        }
                    }
                }

                if(StringUtils.isEmpty(analysisSuggestion.getExit_entrance_cn())&&StringUtils.isEmpty(analysisSuggestion.getExit_entrance_desc())){
                    listSuggestion.add("作案出口为必填项");
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getExit_entrance_cn())){
                        if((analysisSuggestion.getExit_entrance_cn().contains("其他")||analysisSuggestion.getExit_entrance_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getExit_entrance_desc())){
                            listSuggestion.add("作案出口包含其他，手填项必填");
                        }
                    }
                }

                if(StringUtils.isEmpty(analysisSuggestion.getCommission_means_cn())&&StringUtils.isEmpty(analysisSuggestion.getCommission_means_desc())){
                    listSuggestion.add("作案手段为必填项");
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getCommission_means_cn())){
                        if((analysisSuggestion.getCommission_means_cn().contains("其他")||analysisSuggestion.getCommission_means_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getCommission_means_desc())){
                            listSuggestion.add("作案手段包含其他，手填项必填");
                        }
                    }
                }

                if(StringUtils.isEmpty(analysisSuggestion.getIntruding_way_cn())&&StringUtils.isEmpty(analysisSuggestion.getIntruding_way_desc())){
                    listSuggestion.add("侵入方式为必填项");
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getIntruding_way_cn())){
                        if((analysisSuggestion.getIntruding_way_cn().contains("其他")||analysisSuggestion.getIntruding_way_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getIntruding_way_desc())){
                            listSuggestion.add("侵入方式包含其他，手填项必填");
                        }
                    }
                }

                if(StringUtils.isEmpty(analysisSuggestion.getCommission_points_cn())&&StringUtils.isEmpty(analysisSuggestion.getCommission_points_desc())){
                    listSuggestion.add("作案特点为必填项");
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getCommission_points_cn())){
                        if((analysisSuggestion.getCommission_points_cn().contains("其他")||analysisSuggestion.getCommission_points_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getCommission_points_desc())){
                            listSuggestion.add("作案特点包含其他，手填项必填");
                        }
                    }
                }

                if(StringUtils.isEmpty(analysisSuggestion.getCase_property_cn())&&StringUtils.isEmpty(analysisSuggestion.getCase_property_cn())){
                    listSuggestion.add("案件性质为必填项");
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getCase_property_cn())){
                        if((analysisSuggestion.getCase_property_cn().contains("其他")||analysisSuggestion.getCase_property_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getCase_property_cn())){
                            listSuggestion.add("案件性质包含其他，手填项必填");
                        }
                    }
                }

                if(StringUtils.isEmpty(analysisSuggestion.getMotivation_cn())&&StringUtils.isEmpty(analysisSuggestion.getMotivation_cn())){
                    listSuggestion.add("作案动机目的为必填项");
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getMotivation_cn())){
                        if((analysisSuggestion.getMotivation_cn().contains("其他")||analysisSuggestion.getMotivation_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getMotivation_cn())){
                            listSuggestion.add("作案动机目的包含其他，手填项必填");
                        }
                    }
                }


                if(StringUtils.isEmpty(analysisSuggestion.getCommission_desc_content ())){
                    listSuggestion.add("作案过程为必填项");
                }
                if(StringUtils.isEmpty(analysisSuggestion.getCriminal_points_content ())){
                    listSuggestion.add("作案人特点为必填项");
                }
                if(StringUtils.isEmpty(analysisSuggestion.getSuggestion3())){
                    listSuggestion.add("关于侦查方向与范围、侦破措施及途径等意见为必填项");
                }
            }
        }else {
            String [] suggesIds = suggInfoIds.split(",");
            List suggesIdsList = Arrays.asList(suggesIds);
            if(analysisSuggestion==null){
                if(suggesIdsList.contains("2")) {
                    listSuggestion.add("选择对象为必填项");
                }
                if(suggesIdsList.contains("3")){
                    listSuggestion.add("选择处所为必填项");
                }
                if(suggesIdsList.contains("5")) {
                    listSuggestion.add("作案时机为必填项");
                }
                if(suggesIdsList.contains("6")) {
                    listSuggestion.add("作案入口为必填项");
                }
                if(suggesIdsList.contains("7")) {
                    listSuggestion.add("作案出口为必填项");
                }
                if(suggesIdsList.contains("8")) {
                    listSuggestion.add("作案手段为必填项");
                }
                if(suggesIdsList.contains("9")) {
                    listSuggestion.add("侵入方式为必填项");
                }
                if(suggesIdsList.contains("10")) {
                    listSuggestion.add("作案特点为必填项");
                }
                if(suggesIdsList.contains("11")) {
                    listSuggestion.add("案件性质为必填项");
                }
                if(suggesIdsList.contains("12")) {
                    listSuggestion.add("作案动机目的为必填项");
                }
                if(suggesIdsList.contains("15")) {
                    listSuggestion.add("作案过程为必填项");
                }
                if(suggesIdsList.contains("16")) {
                    listSuggestion.add("作案人特点为必填项");
                }
                if(suggesIdsList.contains("17")) {
                    listSuggestion.add("关于侦查方向与范围、侦破措施及途径等意见为必填项");
                }
            }else {

                if(suggesIdsList.contains("2")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getIntention_cn()) && StringUtils.isEmpty(analysisSuggestion.getIntention_desc())) {
                        listSuggestion.add("选择对象为必填项");
                    }else{
                        if(!StringUtils.isEmpty(analysisSuggestion.getIntention_cn())){
                            if((analysisSuggestion.getIntention_cn().contains("其他")||analysisSuggestion.getIntention_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getIntention_desc())){
                                listSuggestion.add("选择对象包含其他，手填项必填");
                            }
                        }
                    }
                }else {
                    if(!StringUtils.isEmpty(analysisSuggestion.getIntention_cn())){
                        if((analysisSuggestion.getIntention_cn().contains("其他")||analysisSuggestion.getIntention_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getIntention_desc())){
                            //修改无
                            analysisSuggestion.setIntention_desc("无");
                        }
                    }
                }
                if(suggesIdsList.contains("3")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getLocation_cn()) && StringUtils.isEmpty(analysisSuggestion.getLocation_desc())) {
                        listSuggestion.add("选择处所为必填项");
                    }else{
                        if(!StringUtils.isEmpty(analysisSuggestion.getLocation_cn())){
                            if((analysisSuggestion.getLocation_cn().contains("其他")||analysisSuggestion.getLocation_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getLocation_desc())){
                                listSuggestion.add("选择处所包含其他，手填项必填");
                            }
                        }
                    }
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getLocation_cn())){
                        if((analysisSuggestion.getLocation_cn().contains("其他")||analysisSuggestion.getLocation_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getLocation_desc())){
                            analysisSuggestion.setLocation_desc("无");
                        }
                    }
                }

                if(suggesIdsList.contains("5")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getCommission_period_cn()) && StringUtils.isEmpty(analysisSuggestion.getCommission_period_desc())) {
                        listSuggestion.add("作案时机为必填项");
                    }else{
                        if(!StringUtils.isEmpty(analysisSuggestion.getCommission_period_cn())){
                            if((analysisSuggestion.getCommission_period_cn().contains("其他")||analysisSuggestion.getCommission_period_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getCommission_period_desc())){
                                listSuggestion.add("作案时机包含其他，手填项必填");
                            }
                        }
                    }
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getCommission_period_cn())){
                        if((analysisSuggestion.getCommission_period_cn().contains("其他")||analysisSuggestion.getCommission_period_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getCommission_period_desc())){
                            analysisSuggestion.setCommission_period_desc("无");
                        }
                    }
                }

                if(suggesIdsList.contains("6")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getEntrance_exit_cn()) && StringUtils.isEmpty(analysisSuggestion.getEntrance_exit_desc())) {
                        listSuggestion.add("作案入口为必填项");
                    }else{
                        if(!StringUtils.isEmpty(analysisSuggestion.getEntrance_exit_cn())){
                            if((analysisSuggestion.getEntrance_exit_cn().contains("其他")||analysisSuggestion.getEntrance_exit_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getEntrance_exit_desc())){
                                listSuggestion.add("作案入口包含其他，手填项必填");
                            }
                        }
                    }
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getEntrance_exit_cn())){
                        if((analysisSuggestion.getEntrance_exit_cn().contains("其他")||analysisSuggestion.getEntrance_exit_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getEntrance_exit_desc())){
                            analysisSuggestion.setEntrance_exit_desc("无");
                        }
                    }
                }

                if(suggesIdsList.contains("7")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getExit_entrance_cn()) && StringUtils.isEmpty(analysisSuggestion.getExit_entrance_desc())) {
                        listSuggestion.add("作案出口为必填项");
                    }else{
                        if(!StringUtils.isEmpty(analysisSuggestion.getExit_entrance_cn())){
                            if((analysisSuggestion.getExit_entrance_cn().contains("其他")||analysisSuggestion.getExit_entrance_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getExit_entrance_desc())){
                                listSuggestion.add("作案出口包含其他，手填项必填");
                            }
                        }
                    }
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getExit_entrance_cn())){
                        if((analysisSuggestion.getExit_entrance_cn().contains("其他")||analysisSuggestion.getExit_entrance_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getExit_entrance_desc())){
                            analysisSuggestion.setExit_entrance_desc("无");
                        }
                    }
                }

                if(suggesIdsList.contains("8")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getCommission_means_cn()) && StringUtils.isEmpty(analysisSuggestion.getCommission_means_desc())) {
                        listSuggestion.add("作案手段为必填项");
                    }else{
                        if(!StringUtils.isEmpty(analysisSuggestion.getCommission_means_cn())){
                            if((analysisSuggestion.getCommission_means_cn().contains("其他")||analysisSuggestion.getCommission_means_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getCommission_means_desc())){
                                listSuggestion.add("作案手段包含其他，手填项必填");
                            }
                        }
                    }
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getCommission_means_cn())){
                        if((analysisSuggestion.getCommission_means_cn().contains("其他")||analysisSuggestion.getCommission_means_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getCommission_means_desc())){
                            analysisSuggestion.setCommission_means_desc("无");
                        }
                    }
                }

                if(suggesIdsList.contains("9")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getIntruding_way_cn()) && StringUtils.isEmpty(analysisSuggestion.getIntruding_way_desc())) {
                        listSuggestion.add("侵入方式为必填项");
                    }else{
                        if(!StringUtils.isEmpty(analysisSuggestion.getIntruding_way_cn())){
                            if((analysisSuggestion.getIntruding_way_cn().contains("其他")||analysisSuggestion.getIntruding_way_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getIntruding_way_desc())){
                                listSuggestion.add("侵入方式包含其他，手填项必填");
                            }
                        }
                    }
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getIntruding_way_cn())){
                        if((analysisSuggestion.getIntruding_way_cn().contains("其他")||analysisSuggestion.getIntruding_way_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getIntruding_way_desc())){
                            analysisSuggestion.setIntruding_way_desc("无");
                        }
                    }
                }

                if(suggesIdsList.contains("10")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getCommission_points_cn()) && StringUtils.isEmpty(analysisSuggestion.getCommission_points_desc())) {
                        listSuggestion.add("作案特点为必填项");
                    }else{
                        if(!StringUtils.isEmpty(analysisSuggestion.getCommission_points_cn())){
                            if((analysisSuggestion.getCommission_points_cn().contains("其他")||analysisSuggestion.getCommission_points_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getCommission_points_desc())){
                                listSuggestion.add("作案特点包含其他，手填项必填");
                            }
                        }
                    }
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getCommission_points_cn())){
                        if((analysisSuggestion.getCommission_points_cn().contains("其他")||analysisSuggestion.getCommission_points_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getCommission_points_desc())){
                            analysisSuggestion.setCommission_points_desc("无");
                        }
                    }
                }

                if(suggesIdsList.contains("11")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getCase_property_cn()) && StringUtils.isEmpty(analysisSuggestion.getCase_property_cn())) {
                        listSuggestion.add("案件性质为必填项");
                    }else{
                        if(!StringUtils.isEmpty(analysisSuggestion.getCase_property_cn())){
                            if((analysisSuggestion.getCase_property_cn().contains("其他")||analysisSuggestion.getCase_property_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getCase_property_cn())){
                                listSuggestion.add("案件性质包含其他，手填项必填");
                            }
                        }
                    }
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getCase_property_cn())){
                        if((analysisSuggestion.getCase_property_cn().contains("其他")||analysisSuggestion.getCase_property_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getCase_property_cn())){
                            analysisSuggestion.setCase_property_desc("无");
                        }
                    }
                }

                if(suggesIdsList.contains("12")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getMotivation_cn()) && StringUtils.isEmpty(analysisSuggestion.getMotivation_cn())) {
                        listSuggestion.add("作案动机目的为必填项");
                    }else{
                        if(!StringUtils.isEmpty(analysisSuggestion.getMotivation_cn())){
                            if((analysisSuggestion.getMotivation_cn().contains("其他")||analysisSuggestion.getMotivation_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getMotivation_cn())){
                                listSuggestion.add("作案动机目的包含其他，手填项必填");
                            }
                        }
                    }
                }else{
                    if(!StringUtils.isEmpty(analysisSuggestion.getMotivation_cn())){
                        if((analysisSuggestion.getMotivation_cn().contains("其他")||analysisSuggestion.getMotivation_cn().contains("其它"))&&StringUtils.isEmpty(analysisSuggestion.getMotivation_cn())){
                            analysisSuggestion.setMotivation_desc("无");
                        }
                    }
                }


                if(suggesIdsList.contains("15")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getCommission_desc_content())) {
                        listSuggestion.add("作案过程为必填项");
                    }
                }
                if(suggesIdsList.contains("16")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getCriminal_points_content())) {
                        listSuggestion.add("作案人特点为必填项");
                    }
                }
                if(suggesIdsList.contains("17")) {
                    if (StringUtils.isEmpty(analysisSuggestion.getSuggestion3())) {
                        listSuggestion.add("关于侦查方向与范围、侦破措施及途径等意见为必填项");
                    }
                }
            }
        }
		map.put("analysis",listSuggestion);
		if(list.isEmpty()&&listSuggestion.isEmpty()){
            int footprintAmount = sceneFootPrintDao.queryCount(caseDetail.getInvestigationid());
            int bioEvienceAmount = sceneBioEvidenceDao.queryCount(caseDetail.getInvestigationid());
            int videoEvienceAmount = sceneVideoEvidenceDao.queryCount(caseDetail.getInvestigationid());
            //修改图片张数
            investigationDao.updateAmount(caseDetail.getInvestigationid(),scenePictureAmount,scenePhotoAmount,footprintAmount,bioEvienceAmount,videoEvienceAmount);
            //修改物证提取人和提取人id
            sceneBioEvidenceDao.updatecCllectedBy(caseDetail.getInvestigationid(),caseDetail.getInvestigator_ids(),caseDetail.getInvestigator());
            sceneVideoEvidenceDao.updatecCllectedBy(caseDetail.getInvestigationid(),caseDetail.getInvestigator_ids(),caseDetail.getInvestigator());
            sceneFootPrintDao.updatecCllectedBy(caseDetail.getInvestigationid(),caseDetail.getInvestigator_ids(),caseDetail.getInvestigator());
            //修改分析意见
            analysisService.addorupdateAnalysis(analysisSuggestion,user);
            //提交
			investigationDao.updateSubmitCase(caseDetail.getInvestigationid());
		}
		return map;
	}

    @Override
    public List<Map<String, String>> selectUserByRegionalism(String regionalism) {
        return investigationDao.selectUserByRegionalism(regionalism);
    }


}
